﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace SNSpirit.Converters
{
    public class BoolVisibilityConverter : IValueConverter
    {
        public BoolVisibilityConverter()
        {
            this.FalseVisibility = Visibility.Collapsed;
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if(value == null)
                throw new ArgumentNullException("value");

            if (value is bool)
            {
                if ((bool)value == true)
                    return Visibility.Visible;
                else
                    return this.FalseVisibility;
            }
            else
            {
                throw new ArgumentException(string.Format("Invalid argument 'value' type:{0}, bool expected", value.GetType().Name));
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                throw new ArgumentNullException("value");
            if (value is Visibility)
            {
                if ((Visibility)value == Visibility.Visible)
                    return true;
                else
                    return false;
            }
            else
            {
                throw new ArgumentException(string.Format("Invalid argument 'value' type:{0}, System.Windows.Visibility expected", value.GetType().Name));
            }
        }

        public Visibility FalseVisibility { get; set; }
    }
}
